package cn.topevery.garden.dal.dao.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.topevery.garden.dal.dao.ProjBidDao;
import cn.topevery.garden.entity.po.ProjBid;
import cn.topevery.garden.entity.query.ProjBidQuery;
import cn.topevery.garden.entity.vo.ProjBidAndProjNameVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * 项目招标表
 *
 * @author code-generate
 * @date 2022-11-02
 */
@Repository
public class ProjBidDaoImpl extends BaseDaoImpl<ProjBid> implements ProjBidDao {
    @Override
    public <P extends DbCsp> List<ProjBid> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<ProjBidAndProjNameVO> listPage(ProjBidQuery query) {
        Integer pageIndex = query.pageIndex - 1;
        StringBuffer table = new StringBuffer();
        table.append("  t_proj_bid tpb  ");
        table.append("  inner join t_proj_basic_info tpbi on tpbi.c_proj_id = tpb.c_proj_id");

        String columns = "tpb.*, tpbi.c_proj_name";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table.toString()).setColumns(columns).setOrderBy("tpb.c_id desc");
        sqlQueryMate
                .where(true, "tpb.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "tpbi.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(ObjectUtil.isNotEmpty(query.getProjId()), "tpbi.c_proj_id", ScriptConditionEnum.Eq, query.getProjId())
                .where(ObjectUtil.isNotEmpty(query.getBidTime()), "tpb.c_bid_time", ScriptConditionEnum.Eq, query.getBidTime())
                .where(ObjectUtil.isNotEmpty(query.getProjName()), "tpbi.c_proj_name", ScriptConditionEnum.Like, query.getProjName())
        ;

        return getDataPager(sqlQueryMate, query.pageSize, pageIndex, ProjBidAndProjNameVO.class);
    }

    @Override
    public List<ProjBidAndProjNameVO> list(ProjBidQuery query) {
        StringBuffer table = new StringBuffer();
        table.append("  t_proj_bid tpb  ");
        table.append("  inner join t_proj_basic_info tpbi on tpbi.c_proj_id = tpb.c_proj_id");

        String columns = "tpb.*, tpbi.c_proj_name";

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table.toString()).setColumns(columns).setOrderBy("tpb.c_id desc");
        sqlQueryMate
                .where(true, "tpb.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(true, "tpbi.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(ObjectUtil.isNotEmpty(query.getProjId()), "tpbi.c_proj_id", ScriptConditionEnum.Eq, query.getProjId())
                .where(ObjectUtil.isNotEmpty(query.getBidTime()), "tpb.c_bid_time", ScriptConditionEnum.Eq, query.getBidTime())
                .where(ObjectUtil.isNotEmpty(query.getProjName()), "tpbi.c_proj_name", ScriptConditionEnum.Like, query.getProjName())
                .where(ObjectUtil.isNotEmpty(query.getIds()), "tpb.c_id", ScriptConditionEnum.In, query.getIds())
        ;
        return selectList(sqlQueryMate, ProjBidAndProjNameVO.class);
    }

    @Override
    public void saveOrUpdate(String userId, Class<ProjBid> entityClass, ProjBid entity) {

    }

    @Override
    public void saveOrUpdate(String userId, Class<ProjBid> entityClass, Collection<ProjBid> list) {

    }

    @Override
    public ProjBid getEntityByGuidId(String projBidId) {
        return getEntityByColumnEqValue(new KeyValue<>("c_proj_bid_id", projBidId));
    }
}
